<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:setBundle basename="messages.messages"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><fmt:message key="siteName"/></title>
</head>

<link rel="stylesheet" href="/Epics/jslib/global.css" />

<body>
	<%@ include file="../Template/TMainLine.jsp" %>
	
	<c:choose>
	<c:when test="${!album.favorite }">
		<h1>${album.title}</h1>
		<table>
			<tr>
				<td>Title:</td>
				<td>${album.title}</td>
			</tr>
			<tr>
				<td>Description:</td>
				<td>${album.description}</td>
			</tr>
			<tr>
				<td>Author:</td>
				<td><a href="SAuthorsProfile?userId=${currentUser.id}">${currentUser.firstName} ${currentUser.lastName}</a></td>
			</tr>
			<c:if test="${!empty user and currentUser.id==user.id}">
				<tr>
					<td colspan="2">
						<form action="SChangeAlbum" method="post" accept-charset="UTF-8">
							<input type="hidden" value="${album.id}" name="albumId" />
							<input type="submit" value="Change album" /><br />
						</form>
					</td>
				</tr>
			</c:if>
			
		</table>
	</c:when><c:otherwise>
		<h1>Favorite</h1>
		<p>Author: <a href="SAuthorsProfile?userId=${currentUser.id}">${currentUser.firstName} ${currentUser.lastName}</a></p>
	</c:otherwise>
	</c:choose>
	
	<c:if test="${!empty photos}">
		<table>
		<c:forEach items="${photos}" var="photo">
			<tr>
				<td><a href="SViewPhoto?photoId=${photo.id }"><img src=".${photo.thumbnailLocation }" alt="${photo.description}"/></a></td>
				<td><a href="SViewPhoto?photoId=${photo.id }">${photo.title }</a></td>
			</tr>
			<tr><td colspan="2">
			<c:choose>
			<c:when test="${!album.favorite }">
				<c:if test="${photo.pub or currentUser.id==user.id}">
					<c:if test="${!empty user and currentUser.id==user.id}">
						<form action="SPhotoDelete" method="post" accept-charset="UTF-8">
							<input type="hidden" value="${photo.id}" name="photoId" />
							<input type="submit" value="Delete photo" /><br />
						</form>
					</c:if>
				</c:if>
			</c:when><c:otherwise>
				<form action="SPhotoRemoveFavorite" method="post" accept-charset="UTF-8">
					<input type="hidden" value="${photo.id}" name="photoId" />
					<input type="hidden" value="${album.id}" name="albumId" />
					<input type="submit" value="Remove from favorites" /><br />
				</form>
			</c:otherwise>
			</c:choose>
			</td></tr>
		</c:forEach>
		</table>
	</c:if>
		
</body>
</html>